home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Pascal / source / NIH Image V1.54 Source / Init.p < prev    next >
Encoding:
Text File  |  1994-01-27  |  43.3 KB  |  1,570 lines  |  [TEXT/PJMM]

  1. unit Initialization;
  2.  
  3. interface
  4.  
  5.  
  6.     uses
  7.         QuickDraw, Palettes, PrintTraps, Slots, globals, Utilities, Graphics, Lut, Strings;
  8.  
  9.     procedure Init;
  10.     procedure AllocateBuffers;
  11.     procedure AllocateArrays;
  12.     procedure SetupMenus;
  13.     procedure GetSettings;
  14.     procedure FindPlugIns;
  15.  
  16.  
  17.  
  18. implementation
  19.  
  20.  
  21.     procedure MakeCursors;
  22.         var
  23.             TempCurH: CursHandle;
  24.     begin
  25.         TempCurH := GetCursor(PickerCursorID);
  26.         if TempCurH <> nil then begin
  27.                 PickerCursor := TempCurH^^;
  28.                 ToolCursor[PickerTool] := PickerCursor;
  29.                 ReleaseResource(handle(TempCurH));
  30.             end;
  31.  
  32.         TempCurH := GetCursor(CrossCursorPlusID);
  33.         if TempCurH <> nil then begin
  34.                 CrossPlusCursor := TempCurH^^;
  35.                 ReleaseResource(handle(TempCurH));
  36.             end;
  37.  
  38.         TempCurH := GetCursor(CrossCursorMinusID);
  39.         if TempCurH <> nil then begin
  40.                 CrossMinusCursor := TempCurH^^;
  41.                 ReleaseResource(handle(TempCurH));
  42.             end;
  43.  
  44.         TempCurH := GetCursor(WandPlusCursorID);
  45.         if TempCurH <> nil then begin
  46.                 WandPlusCursor := TempCurH^^;
  47.                 ReleaseResource(handle(TempCurH));
  48.             end;
  49.  
  50.         TempCurH := GetCursor(WandMinusCursorID);
  51.         if TempCurH <> nil then begin
  52.                 WandMinusCursor := TempCurH^^;
  53.                 ReleaseResource(handle(TempCurH));
  54.             end;
  55.  
  56.         TempCurH := GetCursor(CrossCursorID);
  57.         if TempCurH <> nil then begin
  58.                 ToolCursor[SelectionTool] := TempCurH^^;
  59.                 ToolCursor[FreehandTool] := TempCurH^^;
  60.                 ToolCursor[PolygonTool] := TempCurH^^;
  61.                 ToolCursor[ruler] := TempCurH^^;
  62.                 ToolCursor[PlotTool] := TempCurH^^;
  63.                 ToolCursor[OvalSelectionTool] := TempCurH^^;
  64.                 ToolCursor[LineTool] := TempCurH^^;
  65.                 ToolCursor[AngleTool] := TempCurH^^;
  66.                 ToolCursor[CrossHairTool] := TempCurH^^;
  67.                 ToolCursor[LUTTool] := TempCurH^^;
  68.                 ReleaseResource(handle(TempCurH));
  69.             end;
  70.  
  71.         TempCurH := GetCursor(LUTCursorID);
  72.         if TempCurH <> nil then begin
  73.                 LUTCursor := TempCurH^^;
  74.                 ReleaseResource(handle(TempCurH));
  75.             end;
  76.  
  77.         TempCurH := GetCursor(gmCursorID);
  78.         if TempCurH <> nil then begin
  79.                 gmCursor := TempCurH^^;
  80.                 ReleaseResource(handle(TempCurH));
  81.             end;
  82.  
  83.         TempCurH := GetCursor(GrabberCursorID);
  84.         if TempCurH <> nil then begin
  85.                 ToolCursor[Grabber] := TempCurH^^;
  86.                 ReleaseResource(handle(TempCurH));
  87.             end;
  88.  
  89.         TempCurH := GetCursor(PencilCursorID);
  90.         if TempCurH <> nil then begin
  91.                 ToolCursor[Pencil] := TempCurH^^;
  92.                 ReleaseResource(handle(TempCurH));
  93.             end;
  94.  
  95.         TempCurH := GetCursor(GlassCursorPlusID);
  96.         if TempCurH <> nil then begin
  97.                 ToolCursor[MagnifyingGlass] := TempCurH^^;
  98.                 ReleaseResource(handle(TempCurH));
  99.             end;
  100.  
  101.         TempCurH := GetCursor(GlassCursorMinusID);
  102.         if TempCurH <> nil then begin
  103.                 GlassMinusCursor := TempCurH^^;
  104.                 ReleaseResource(handle(TempCurH));
  105.             end;
  106.  
  107.         TempCurH := GetCursor(BucketCursorID);
  108.         if TempCurH <> nil then begin
  109.                 ToolCursor[PaintBucket] := TempCurH^^;
  110.                 ReleaseResource(handle(TempCurH));
  111.             end;
  112.  
  113.         TempCurH := GetCursor(WandCursorID);
  114.         if TempCurH <> nil then begin
  115.                 ToolCursor[Wand] := TempCurH^^;
  116.                 ReleaseResource(handle(TempCurH));
  117.             end;
  118.  
  119.         TempCurH := GetCursor(TextCursorID);
  120.         if TempCurH <> nil then begin
  121.                 ToolCursor[TextTool] := TempCurH^^;
  122.                 ReleaseResource(handle(TempCurH));
  123.             end;
  124.  
  125.         TempCurH := GetCursor(EraserCursorID);
  126.         if TempCurH <> nil then begin
  127.                 ToolCursor[eraser] := TempCurH^^;
  128.                 ReleaseResource(handle(TempCurH));
  129.             end;
  130.  
  131.         TempCurH := GetCursor(SprayCursorID);
  132.         if TempCurH <> nil then begin
  133.                 ToolCursor[SprayCanTool] := TempCurH^^;
  134.                 ReleaseResource(handle(TempCurH));
  135.             end;
  136.  
  137.         TempCurH := GetCursor(BrushCursorID);
  138.         if TempCurH <> nil then begin
  139.                 ToolCursor[brush] := TempCurH^^;
  140.                 ReleaseResource(handle(TempCurH));
  141.             end;
  142.  
  143.         TempCurH := GetCursor(WatchCursor);
  144.         if TempCurH <> nil then begin
  145.                 watch := TempCurH^^;
  146.                 ReleaseResource(handle(TempCurH));
  147.             end;
  148.     end;
  149.  
  150.  
  151.     procedure MakeToolsBitMap;
  152.   {Creates the offscreen bitmap used to draw the tool palette.}
  153.         var
  154.             tPort: GrafPtr;
  155.             TempPort: GrafPort;
  156.             PicH: PicHandle;
  157.             FrameRect: rect;
  158.             fwidth, fheight: integer;
  159.     begin
  160.         PicH := GetPicture(130);
  161.         if PicH = nil then
  162.             ExitToShell;
  163.         FrameRect := PicH^^.PicFrame;
  164.         with FrameRect do begin
  165.                 fwidth := right - left;
  166.                 fheight := bottom - top;
  167.             end;
  168.         GetPort(tPort);
  169.         OpenPort(@TempPort);
  170.         with ToolBits, FrameRect do begin
  171.                 baseAddr := NewPtr((fwidth * fheight) div 8);
  172.                 if baseAddr = nil then
  173.                     ExitToShell;
  174.                 rowBytes := fwidth div 8;
  175.                 SetRect(bounds, 0, 0, fwidth, fheight);
  176.             end;
  177.         SetPortBits(ToolBits);
  178.         DrawPicture(PicH, ToolBits.bounds);
  179.         DisposHandle(handle(PicH));
  180.         ClosePort(@TempPort);
  181.         SetPort(tPort);
  182.     end;
  183.  
  184.  
  185.     procedure InitTools;
  186.         var
  187.             ToolTop, LinesTop, i: integer;
  188.             Tool: ToolType;
  189.     begin
  190.         MakeToolsBitmap;
  191.         FirstTool := MagnifyingGlass;
  192.         LastTool := CrossHairTool;
  193.         CurrentTool := SelectionTool;
  194.         isSelectionTool := true;
  195.         PreviousTool := CurrentTool;
  196.         ToolTop := 0;
  197.         for tool := FirstTool to LastTool do
  198.             with ToolRect[tool] do begin
  199.                     top := ToolTop;
  200.                     bottom := top + tmiddle;
  201.                     if odd(ord(tool) + 1) then
  202.                         left := 0
  203.                     else begin
  204.                             left := tmiddle;
  205.                             ToolTop := ToolTop + tmiddle;
  206.                         end;
  207.                     right := left + tmiddle;
  208.                 end;
  209.         ToolTime := 0;
  210.         LutTime := 0;
  211.         StartOfLines := ToolRect[LastTool].bottom - 1;
  212.         LinesTop := StartOfLines + 10;
  213.         for i := 1 to nLineTypes do
  214.             with lines[i] do begin
  215.                     left := LinesLeft;
  216.                     top := LinesTop;
  217.                     right := LinesRight;
  218.                     case i of
  219.                         1, 2, 3, 4: 
  220.                             bottom := top + i;
  221.                         5: 
  222.                             bottom := top + 6;
  223.                         6: 
  224.                             bottom := top + 8
  225.                     end;
  226.                     LinesTop := bottom + 4;
  227.                 end;
  228.         LineWidth := 1;
  229.         LineIndex := 1;
  230.         with CheckRect do begin
  231.                 left := 0;
  232.                 top := StartOfLines;
  233.                 right := LinesLeft;
  234.                 bottom := theight;
  235.             end;
  236.     end;
  237.  
  238.  
  239.     procedure AllocateBuffers;
  240.         var
  241.             tPort: GrafPtr;
  242.             err: OSErr;
  243.             BufSizeStr: str255;
  244.             atemp: integer;
  245.     begin
  246.         GetPort(tPort);
  247.         NumToString(BufferSize div 1024, BufSizeStr);
  248.         BigBufSize := BufferSize * 2;
  249.         if FreeMem > (BigBufSize + 300000) then
  250.             BigBuf := NewPtr(BigBufSize)
  251.         else
  252.             BigBuf := nil;
  253.         if BigBuf = nil then
  254.             BigBufSize := 0;
  255.         if BigBuf <> nil then
  256.             UndoBuf := BigBuf
  257.         else begin
  258.                 if FreeMem > (BufferSize + 200000) then
  259.                     UndoBuf := NewPtr(BufferSize)
  260.                 else
  261.                     UndoBuf := nil;
  262.             end;
  263.         if UndoBuf <> nil then
  264.             UndoBufSize := BufferSize
  265.         else begin
  266.                 PutMessage(concat('There is not enough memory available to allocate the ', BufSizeStr, 'K Undo buffer. Many operations may fail or be Undoable.'));
  267.                 UndoBufSize := 0;
  268.             end;
  269.         if BigBuf <> nil then
  270.             ClipBuf := ptr(ord4(BigBuf) + BufferSize)
  271.         else begin
  272.                 if FreeMem > (BufferSize + 300000) then
  273.                     ClipBuf := NewPtr(BufferSize)
  274.                 else
  275.                     ClipBuf := nil;
  276.             end;
  277.         UndoInfoRec := NoInfo^;
  278.         UndoInfo := @UndoInfoRec;
  279.         if UndoBuf <> nil then
  280.             with UndoInfo^ do begin
  281.                     roiRgn := NewRgn;
  282.                     PicBaseAddr := UndoBuf;
  283.                     osPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  284.                     OpenCPort(osPort);
  285.                     osPort^.portPixMap^^.BaseAddr := PicBaseAddr;
  286.                     SetPalette(WindowPtr(osPort), ExplicitPalette, false);
  287.                 end;
  288.         if ClipBuf <> nil then begin
  289.                 ClipBufSize := BufferSize;
  290.                 ClipBufInfoRec := NoInfo^;
  291.                 ClipBufInfo := @ClipBufInfoRec;
  292.                 with ClipBufInfo^ do begin
  293.                         roiRgn := NewRgn;
  294.                         PicBaseAddr := ClipBuf;
  295.                         osPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  296.                         OpenCPort(osPort);
  297.                         osPort^.portPixMap^^.BaseAddr := PicBaseAddr;
  298.                         BytesPerRow := 0;
  299.                         SetPalette(WindowPtr(osPort), ExplicitPalette, false);
  300.                     end;
  301.             end
  302.         else begin
  303.                 PutMessage(concat('There is not enough memory available to allocate the ', BufSizeStr, 'K Clipboard Buffer. Many operations, including Copy and Paste, may fail.'));
  304.                 ClipBufSize := 0;
  305.             end;
  306.         SetPort(tPort);
  307.     end;
  308.  
  309.  
  310.     procedure AllocateArrays;
  311.         var
  312.             nItems: LongInt;
  313.             i: integer;
  314.  
  315.         procedure Abort;
  316.         begin
  317.             PutMessage('Not enough memory available to allocate arrays.');
  318.             ExitToShell;
  319.         end;
  320.  
  321.     begin
  322.         PlotData := rLinePtr(NewPtr(SizeOf(rLineType)));
  323.         if PlotData = nil then
  324.             abort;
  325.         BlankLine := LinePtr(NewPtr(MaxLine));
  326.         if BlankLine = nil then
  327.             abort;
  328.         for i := 0 to MaxLine - 1 do
  329.             BlankLine^[i] := WhiteIndex;
  330.         xCoordinates := xCoordinatesPtr(NewPtr(SizeOf(CoordinatesType)));
  331.         if xCoordinates = nil then
  332.             abort;
  333.         yCoordinates := yCoordinatesPtr(NewPtr(SizeOf(CoordinatesType)));
  334.         if yCoordinates = nil then
  335.             abort;
  336.         nItems := MaxMeasurements + 1;
  337.         mean := meanPtr(NewPtr(nItems * SizeOf(real)));
  338.         if mean = nil then
  339.             abort;
  340.         sd := sdPtr(NewPtr(nItems * SizeOf(real)));
  341.         if sd = nil then
  342.             abort;
  343.         PixelCount := PixelCountPtr(NewPtr(nItems * SizeOf(LongInt)));
  344.         if PixelCount = nil then
  345.             abort;
  346.         mArea := AreaPtr(NewPtr(nItems * SizeOf(real)));
  347.         if mArea = nil then
  348.             abort;
  349.         mode := modePtr(NewPtr(nItems * SizeOf(real)));
  350.         if mode = nil then
  351.             abort;
  352.         IntegratedDensity := IntegratedDensityPtr(NewPtr(nItems * SizeOf(real)));
  353.         if IntegratedDensity = nil then
  354.             abort;
  355.         idBackground := idBackgroundPtr(NewPtr(nItems * SizeOf(real)));
  356.         if idBackground = nil then
  357.             abort;
  358.         xcenter := xcenterPtr(NewPtr(nItems * SizeOf(real)));
  359.         if xcenter = nil then
  360.             abort;
  361.         ycenter := ycenterPtr(NewPtr(nItems * SizeOf(real)));
  362.         if ycenter = nil then
  363.             abort;
  364.         MajorAxis := MajorAxisPtr(NewPtr(nItems * SizeOf(real)));
  365.         if MajorAxis = nil then
  366.             abort;
  367.         MinorAxis := MinorAxisPtr(NewPtr(nItems * SizeOf(real)));
  368.         if MinorAxis = nil then
  369.             abort;
  370.         orientation := orientationPtr(NewPtr(nItems * SizeOf(real)));
  371.         if orientation = nil then
  372.             abort;
  373.         mMin := MinPtr(NewPtr(nItems * SizeOf(real)));
  374.         if mMin = nil then
  375.             abort;
  376.         mMax := MaxPtr(NewPtr(nItems * SizeOf(real)));
  377.         if mMax = nil then
  378.             abort;
  379.         plength := plengthPtr(NewPtr(nItems * SizeOf(real)));
  380.         if plength = nil then
  381.             abort;
  382.         User1 := User1Ptr(NewPtr(nItems * SizeOf(real)));
  383.         if User1 = nil then
  384.             abort;
  385.         for i := 0 to MaxMeasurements do
  386.             User1^[i] := 0.0;
  387.         User2 := User2Ptr(NewPtr(nItems * SizeOf(real)));
  388.         if User2 = nil then
  389.             abort;
  390.         for i := 0 to MaxMeasurements do
  391.             User2^[i] := 0.0;
  392.         ClearResults(0);
  393.         if FreeMem < MinFree then
  394.             Abort;
  395.     end;
  396.  
  397.  
  398.     function OpenWD (vRefNum: integer; dirID: LongInt; procID: LongInt; var wdRefNum: integer): OSErr;
  399. {Converts a volume reference number and directory ID into a working directory reference number. See TN 218.}
  400.         var
  401.             theWD: WDPBRec;
  402.             err: OSErr;
  403.     begin
  404.         with theWD do begin
  405.                 ioCompletion := nil;
  406.                 ioNamePtr := nil;
  407.                 ioVRefNum := VRefNum;
  408.                 ioWDProcID := 0;
  409.                 ioWDDirID := DirID;
  410.                 err := PBOpenWD(@theWD, false);
  411.                 if err = NoErr then
  412.                     wdRefNum := ioVRefNum;
  413.                 OpenWD := err;
  414.             end; {with}
  415.     end;
  416.  
  417.  
  418.     procedure GetKernelsWorkingDir (var settings: SettingsType);
  419.         var
  420.             wdRefNum: integer;
  421.             err: OSErr;
  422.     begin
  423.         with settings do
  424.             if sKernelsVRefNum <> 0 then begin
  425.                     err := OpenWD(sKernelsVRefNum, sKernelsDirID, 0, wdRefNum);
  426.                     if err = NoErr then
  427.                         KernelsRefNum := wdRefNum;
  428.           {ShowMessage(concat('KernelsRefNum=', long2str(KernelsRefNum), cr, 'vRefNum=', long2str(sKernelsVRefNum), cr, 'DirID=', long2str(sKernelsDirID)));}
  429.                 end;
  430.     end;
  431.  
  432.  
  433.     procedure GetDefaultWorkingDir (var settings: SettingsType);
  434.         var
  435.             wdRefNum: integer;
  436.             err: OSErr;
  437.     begin
  438.         with settings do
  439.             if sDefaultVRefNum <> 0 then begin
  440.                     err := OpenWD(sDefaultVRefNum, sDefaultDirID, 0, wdRefNum);
  441.                     if err = NoErr then
  442.                         DefaultRefNum := wdRefNum;
  443.                 end;
  444.     end;
  445.  
  446.  
  447.     procedure GetSettings;
  448.         var
  449.             err: OSErr;
  450.             f: integer;
  451.             ByteCount: LongInt;
  452.             ok: boolean;
  453.             size: LongInt;
  454.             settings: SettingsType;
  455.     begin
  456.         err := fsopen(PrefsName, SystemRefNum, f);
  457.         if err <> NoErr then
  458.             exit(GetSettings);
  459.         err := GetEof(f, ByteCount);
  460.         if ByteCount > SizeOf(settings) then
  461.             ByteCount := SizeOf(settings);
  462.         err := fsRead(f, ByteCount, @settings);
  463.         if err <> NoErr then
  464.             exit(GetSettings);
  465.         err := fsClose(f);
  466.         with settings, info^ do begin
  467.                 if sID <> 'IMAG' then begin
  468.                         PutMessage('The Image Prefs file in the System folder is corrupted. Please delete it and try again.');
  469.                         exitToShell;
  470.                     end;
  471.                 if (ForegroundIndex <> sForegroundIndex) or (BackgroundIndex <> sBackgroundIndex) then begin
  472.                         SetForegroundColor(sForegroundIndex);
  473.                         SetBackgroundColor(sBackgroundIndex);
  474.                     end;
  475.                 BrushHeight := sBrushHeight;
  476.                 BrushWidth := sBrushWidth;
  477.                 SprayCanDiameter := sSprayCanDiameter;
  478.                 SprayCanRadius := SprayCanDiameter div 2;
  479.                 SprayCanRadius2 := SprayCanRadius * SprayCanRadius;
  480.                 CurrentFontID := sCurrentFontID;
  481.                 CurrentStyle := SCurrentStyle;
  482.                 CurrentSize := sCurrentSize;
  483.                 TextJust := sTextJust;
  484.                 TextBack := sTextBack;
  485.                 nExtraColors := sNExtraColors;
  486.                 ExtraColors := sExtraColors;
  487.                 InvertVideo := sInvertVideo;
  488.                 Measurements := sMeasurements;
  489.                 InvertPlots := sInvertPlots;
  490.                 AutoScalePlots := sAutoScalePlots;
  491.                 LinePlot := sLinePlot;
  492.                 DrawPlotLabels := sDrawPlotLabels;
  493.                 FixedSizePlot := sFixedSizePlot;
  494.                 ProfilePlotWidth := sProfilePlotWidth;
  495.                 ProfilePlotHeight := sProfilePlotHeight;
  496.                 FramesToAverage := sFramesToAverage;
  497.                 NewPicWidth := sNewPicWidth;
  498.                 NewPicHeight := sNewPicHeight;
  499.                 BufferSize := sBufferSize;
  500.                 MaxScionWidth := sMaxScionWidth;
  501.                 ThresholdToForeground := sThresholdToForeground;
  502.                 NonThresholdToBackground := sNonThresholdToBackground;
  503.                 VideoChannel := sVideoChannel;
  504.                 WhatToImport := sWhatToImport;
  505.                 ImportCustomWidth := sImportCustomWidth;
  506.                 ImportCustomHeight := sImportCustomHeight;
  507.                 ImportCustomOffset := sImportCustomOffset;
  508.         {WandAutoMeasure := sWandAutoMeasure;}
  509.                 WandAdjustAreas := sWandAdjustAreas;
  510.                 BinaryIterations := sBinaryIterations;
  511.                 ScaleArithmetic := sScaleArithmetic;
  512.                 InvertPixelValues := sInvertPixelValues;
  513.                 InvertYCoordinates := sInvertYCoordinates;
  514.                 FieldWidth := sFieldWidth;
  515.                 precision := sPrecision;
  516.                 MinParticleSize := sMinParticleSize;
  517.                 MaxParticleSize := sMaxParticleSize;
  518.                 IgnoreParticlesTouchingEdge := sIgnoreParticlesTouchingEdge;
  519.                 LabelParticles := sLabelParticles;
  520.                 OutlineParticles := sOutlineParticles;
  521. {IncludeHoles := sIncludeHoles;}
  522.                 OscillatingMovies := sOscillatingMovies;
  523.                 DriverHalftoning := sDriverHalftoning;
  524.                 MaxMeasurements := sMaxMeasurements;
  525.                 ImportCustomDepth := sImportCustomDepth;
  526.                 ImportSwapBytes := sImportSwapBytes;
  527.                 ImportCalibrate := sImportCalibrate;
  528.                 ImportAutoscale := sImportAutoscale;
  529.                 ShowHeadings := sShowHeadings;
  530.                 if sVersion >= 140 then begin
  531.                         ProfilePlotMin := sProfilePlotMin;
  532.                         ProfilePlotMax := sProfilePlotMax;
  533.                         ImportMin := sImportMin;
  534.                         ImportMax := sImportMax;
  535.                         HighlightSaturatedPixels := sHighlightPixels;
  536.                     end;
  537.                 if sVersion >= 141 then begin
  538.                         BallRadius := sBallRadius;
  539.                         FasterBackgroundSubtraction := sFasterBackgroundSubtraction;
  540.                         ScaleConvolutions := sScaleConvolutions;
  541.                     end;
  542.                 if sVersion >= 142 then begin
  543.                         BinaryCount := sBinaryCount;
  544.                         BinaryThreshold := BinaryCount * 255;
  545.                         if (sLUTMode = Pseudocolor) and (sColorTable <> CustomTable) and (sColorTable <= Spectrum) then begin
  546.                                 SwitchColorTables(GetColorTableItem(sColorTable), false);
  547.                                 ColorStart := sColorStart;
  548.                                 ColorEnd := sColorEnd;
  549.                                 LutMode := Pseudocolor;
  550.                                 if sInvertedTable then
  551.                                     InvertPalette;
  552.                                 UpdateLut;
  553.                             end;
  554.                     end;
  555.                 if sVersion >= 144 then begin
  556.                         HalftoneFrequency := sHalftoneFrequency;
  557.                         HalftoneAngle := sHalftoneAngle;
  558.                         HalftoneDotFunction := sHalftoneDotFunction;
  559.                     end;
  560.                 if sVersion >= 146 then begin
  561.                         LG3DacLow := sLG3DacLow;
  562.                         LG3DacHigh := sLG3DacHigh;
  563.                     end;
  564.                 if (sVersion >= 147) and (FrameGrabber = ScionLG3) then
  565.                     SyncMode := sSyncMode;
  566.                 if sVersion >= 149 then begin
  567.                         SwitchLUTOnSuspend := sSwitchLUTOnSuspend;
  568.                         VideoRateAveraging := sVideoRateAveraging;
  569.                     end;
  570.                 if sVersion >= 150 then begin
  571.                         ImportInvert := sImportInvert;
  572.                     end;
  573.                 if sVersion >= 152 then begin
  574.                         if sTextCreator[1] <> chr(0) then
  575.                             TextCreator := sTextCreator;
  576.                     end;
  577.                 GetKernelsWorkingDir(settings);
  578.                 GetDefaultWorkingDir(settings);
  579.                 UpdateFitEllipse;
  580.             end; {with settings, info^}
  581.         case info^.LUTMode of
  582.             PseudoColor, ColorLut, CustomGrayscale: 
  583.                 UpdateLUT;
  584.             OldAppleDefault: 
  585.                 ok := LoadCLUTResource(AppleDefaultCLUT);
  586.             otherwise
  587.         end;
  588.         if nExtraColors > 0 then
  589.             RedrawLUTWindow;
  590.         if InvertPixelValues then
  591.             InvertGrayLevels;
  592.     end;
  593.  
  594.  
  595.     procedure MakePatterns;
  596. {Creates the patterns used to create the "marching ants". Thanks to}
  597. { Seth Snyder on CompuServe for the example.}
  598.         var
  599.             i, j: Integer;
  600.     begin
  601.         j := 0;
  602.         for i := 0 to 7 do begin
  603.                 pat[i][(j + 0) mod 8] := $1F;
  604.                 pat[i][(j + 1) mod 8] := $3E;
  605.                 pat[i][(j + 2) mod 8] := $7C;
  606.                 pat[i][(j + 3) mod 8] := $F8;
  607.                 pat[i][(j + 4) mod 8] := $F1;
  608.                 pat[i][(j + 5) mod 8] := $E3;
  609.                 pat[i][(j + 6) mod 8] := $C7;
  610.                 pat[i][(j + 7) mod 8] := $8F;
  611.                 j := j + 1;
  612.             end;
  613.         PatIndex := 0;
  614.     end;
  615.  
  616.  
  617.     procedure InitExtraColors;
  618.         var
  619.             i, j, ctop, cbottom, entry: integer;
  620.             tRect: rect;
  621.     begin
  622.         with ExtraColors[1] do begin
  623.                 red := -1;
  624.                 green := 0;
  625.                 blue := 0;
  626.             end;
  627.         with ExtraColors[2] do begin
  628.                 red := 0;
  629.                 green := -1;
  630.                 blue := 0;
  631.             end;
  632.         with ExtraColors[3] do begin
  633.                 red := 0;
  634.                 green := 0;
  635.                 blue := -1;
  636.             end;
  637.         with ExtraColors[4] do begin
  638.                 red := -1;
  639.                 green := -1;
  640.                 blue := 0;
  641.             end;
  642.         with ExtraColors[5] do begin
  643.                 red := 0;
  644.                 green := -1;
  645.                 blue := -1;
  646.             end;
  647.         with ExtraColors[6] do begin
  648.                 red := -1;
  649.                 green := 0;
  650.                 blue := -1;
  651.             end;
  652.         ctop := 256;
  653.         cbottom := ctop + ExtraColorsHeight;
  654.         for i := 1 to MaxExtraPlus2 do begin
  655.                 SetRect(tRect, 0, ctop, cwidth, cbottom);
  656.                 ExtraColorsRect[i] := tRect;
  657.                 ctop := ctop + ExtraColorsHeight;
  658.                 cbottom := cbottom + ExtraColorsHeight;
  659.             end;
  660.         ExtraColorsEntry[1] := WhiteIndex;
  661.         ExtraColorsEntry[2] := BlackIndex;
  662.         entry := FirstExtraColorsEntry;
  663.         j := 3;
  664.         for i := 1 to MaxExtraColors do begin
  665.                 ExtraColorsEntry[j] := entry;
  666.                 j := j + 1;
  667.                 Entry := Entry + 1;
  668.             end;
  669.     end;
  670.  
  671.  
  672.     function GetSlotBase (id: integer): LongInt;
  673.   {Returns the slot base address of the NuBus card with the specified id. The address}
  674.   {returned is in the form $Fss00000, which is valid in both 24 and 32-bit modes.}
  675.   {Returns 0 if a card with the given id is not found.}
  676.         type
  677.             SPRAMRecord = packed record
  678.                     BoardId: integer;
  679.                     VenderUse: packed array[1..6] of SignedByte;
  680.                 end;
  681.         var
  682.             SlotBlock: SpBlock;
  683.             sparm: SPRAMRecord;
  684.             SparmAddr: LongInt;
  685.             i: integer;
  686.             err: OSErr;
  687.     begin
  688.         with SlotBlock do begin
  689.                 SparmAddr := LongInt(@sparm);
  690.                 spResult := SparmAddr;
  691.                 for i := 9 to 15 do begin
  692.                         spSlot := i;
  693.                         err := sReadPRAMRec(@SlotBlock);
  694.                         if sparm.BoardID = id then begin
  695.                                 GetSlotBase := bor($F0000000, spSlot * $100000 + spSlot * $1000000);
  696.                                 exit(GetSlotBase)
  697.                             end;
  698.                     end;
  699.                 GetSlotBase := 0;
  700.             end;
  701.     end;
  702.  
  703.  
  704.     procedure SetupFGPort;
  705. {So we can use CopyBits, this routine sets up a color graf port that}
  706. {uses the memory on the frame grabber board as the PixMap.}
  707.         const
  708.             baseAddr32 = 4;
  709.         var
  710.             tPort: GrafPtr;
  711.             trect: rect;
  712.     begin
  713.         GetPort(tPort);
  714.         fgPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  715.         OpenCPort(fgPort);
  716.         SetRect(trect, 0, 0, fgWidth, fgHeight);
  717.         with fgPort^ do begin
  718.                 with PortPixMap^^ do begin
  719.                         BaseAddr := ptr(fgSlotBase);
  720.                         bounds := trect;
  721.                         RowBytes := BitOr(fgRowBytes, $8000);
  722.                         pmVersion := baseAddr32; {Needed for 8*24 GC card. See TN 275.}
  723.                     end;
  724.                 PortRect := trect;
  725.                 RectRgn(visRgn, trect);
  726.             end;
  727.         SetPort(tPort);
  728.         SetPalette(WindowPtr(fgPort), ExplicitPalette, false);
  729.     end;
  730.  
  731.  
  732.     function is50HzLG3: boolean;
  733.         const
  734.             BoardResourceID = 1;
  735.             VendorInfoID = 36;
  736.             PartNumberID = 4;
  737.             PartNumber50Hz = 'LG-3 50Hz';
  738.         var
  739.             SlotBlock: SpBlock;
  740.             err: OSErr;
  741.             PartNumberPtr: StringPtr;
  742.     begin
  743.         is50HzLG3 := false;
  744.         SlotBlock.spSlot := byte(bsr(band(fgSlotBase, $0f000000), 24));
  745.         SlotBlock.spId := BoardResourceID;
  746.         SlotBlock.spExtDev := 0;
  747.         err := SRsrcInfo(@SlotBlock);
  748.         if err <> 0 then
  749.             exit(is50HzLG3);
  750.         SlotBlock.spId := VendorInfoID;
  751.         err := SFindStruct(@SlotBlock);
  752.         if err <> 0 then
  753.             exit(is50HzLG3);
  754.         SlotBlock.spID := PartNumberID;
  755.         err := SGetCString(@SlotBlock);
  756.         if err <> 0 then
  757.             exit(is50HzLG3);
  758.         PartNumberPtr := C2PStr(SlotBlock.spResult);
  759.         if PartNumberPtr^ = PartNumber50Hz then
  760.             is50HzLG3 := true;
  761.     end;
  762.  
  763.  
  764.     procedure CheckLG3Buffer;
  765.         type
  766.             LongintPtr = ^Longint;
  767.         const
  768.             Pattern = $A596A596;
  769.         var
  770.             BufferPtr: LongintPtr;
  771.     begin
  772.         BufferPtr := LongintPtr(fgSlotBase);
  773.         BufferReg^ := 0;
  774.         BufferPtr^ := Pattern;
  775.         if BufferPtr^ <> Pattern then begin
  776.                 MaxLG3Frames := 0;
  777.                 exit(CheckLG3Buffer);
  778.             end;
  779.         BufferReg^ := 2;
  780.         if BufferPtr^ = Pattern then begin
  781.                 MaxLG3Frames := 2;
  782.                 exit(CheckLG3Buffer);
  783.             end;
  784.         BufferReg^ := 8;
  785.         if BufferPtr^ = Pattern then begin
  786.                 MaxLG3Frames := 8;
  787.                 exit(CheckLG3Buffer);
  788.             end;
  789.         BufferReg^ := 32;
  790.         if BufferPtr^ = Pattern then begin
  791.                 MaxLG3Frames := 32;
  792.                 exit(CheckLG3Buffer);
  793.             end;
  794.         MaxLG3Frames := 128;
  795.     end;
  796.  
  797.  
  798.     procedure LookForFrameGrabbers;
  799.         const
  800.             ControlRegOffset = $80000;
  801.             ChannelRegOffset = $80004;
  802.             LG3ControlRegOffset = $C0000;
  803.             LG3ChannelRegOffset = $C0008;
  804.             BufferRegOffset = $C0004;
  805.             DacHighRegOffset = $C000C;
  806.             DacLowRegOffset = $C0010;
  807.             DacARegOffset = $C0014;
  808.             DacBRegOffset = $C0018;
  809.             DT2255id = $11A;
  810.             Scion1000id = $14B;
  811.             Scion1200id = $222;
  812.             ScionLG3id = $48b;
  813.             PalBufferSize = 393216; {768 x 512}
  814.         var
  815.             err: OSErr;
  816.             tPort: GrafPtr;
  817.             OptionKeyIsDown: boolean;
  818.     begin
  819.         OptionKeyIsDown := OptionKeyDown;
  820.         FrameGrabber := NoFrameGrabber;
  821.         fgPort := nil;
  822.         fgSlotBase := GetSlotBase(Scion1000id);
  823.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  824.                 FrameGrabber := Scion;
  825.                 exit(LookForFrameGrabbers);
  826.             end;
  827.         fgSlotBase := GetSlotBase(Scion1200id);
  828.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  829.                 FrameGrabber := Scion;
  830.                 exit(LookForFrameGrabbers);
  831.             end;
  832.         fgSlotBase := GetSlotBase(ScionLG3id);
  833.         if (fgSlotBase <> 0) and not OptionKeyIsDown then begin
  834.                 FrameGrabber := ScionLG3;
  835.                 ControlReg := ptr(fgSlotBase + LG3ControlRegOffset);
  836.                 ChannelReg := ptr(fgSlotBase + LG3ChannelRegOffset);
  837.                 BufferReg := ptr(fgSlotBase + BufferRegOffset);
  838.                 DacHighReg := ptr(fgSlotBase + DacHighRegOffset);
  839.                 DacLowReg := ptr(fgSlotBase + DacLowRegOffset);
  840.                 DacAReg := ptr(fgSlotBase + DacARegOffset);
  841.                 DacBReg := ptr(fgSlotBase + DacBRegOffset);
  842.                 fgWidth := 640;
  843.                 fgHeight := 480;
  844.                 if is50HzLG3 then begin
  845.                         fgWidth := 768;
  846.                         fgHeight := 512;
  847.                         if BufferSize < PalBufferSize then
  848.                             BufferSize := PalBufferSize;
  849.                     end;
  850.                 CheckLG3Buffer;
  851.                 SetupFGPort;
  852.                 ResetScionLG3;
  853.                 exit(LookForFrameGrabbers);
  854.             end;
  855.         fgSlotBase := GetSlotBase(DT2255id);
  856.         if fgSlotBase <> 0 then begin
  857.                 FrameGrabber := QuickCapture;
  858.                 ControlReg := ptr(fgSlotBase + ControlRegOffset);
  859.                 ChannelReg := ptr(fgSlotBase + ControlRegOffset + 4);
  860.                 fgWidth := 640;
  861.                 fgHeight := 480;
  862.                 if band(ChannelReg^, 8) = 8 then begin {Check for 50Hz(PAL) card}
  863.                         fgWidth := 768;
  864.                         fgHeight := 512;
  865.                         if BufferSize < PalBufferSize then
  866.                             BufferSize := PalBufferSize;
  867.                     end;
  868.                 SetupFGPort;
  869.                 ResetQuickCapture;
  870.                 exit(LookForFrameGrabbers);
  871.             end;
  872.     end;
  873.  
  874.  
  875.     procedure CheckBits;
  876.         const
  877.             QD32Trap = $AB03;
  878.             UnimplementedTrap = $A89F;
  879.         var
  880.             MainDevice: GDHandle;
  881.             ScreenPixMap: PixMapHandle;
  882.             myEnvRec: SysEnvRec;
  883.             err: OSErr;
  884.     begin
  885.         err := SysEnvirons(1, myEnvRec);
  886.         if err <> envNotPresent then
  887.             with MyEnvRec do begin
  888.                     if not HasColorQD then begin
  889.                             PutMessage('Sorry, Image requires a Macintosh with Color QuickDraw.');
  890.                             ExitToShell;
  891.                         end;
  892.                     if not HasFPU and UsingFPU then begin
  893.                             PutMessage('Use the NonFPU version of Image on Macs without a floating-point coprocessor.');
  894.                             ExitToShell;
  895.                         end;
  896.                     OldSystem := systemVersion < $0605;
  897.                     System7 := systemVersion >= $0700;
  898.                     SystemRefnum := sysVRefNum;
  899.                 end;
  900.         Has32BitQuickDraw := nGetTrapAddress(QD32Trap, ToolTrap) <> nGetTrapAddress(UnimplementedTrap, ToolTrap);
  901.         MainDevice := GetMainDevice;
  902.         if MainDevice^^.gdPmap^^.PixelSize <> 8 then begin
  903.                 PutMessage('To run Image, the main monitor(the one with the menu bar) must be set to 256 colors or 256 gray levels.');
  904.                 ExitToShell;
  905.             end;
  906.         ScreenPixMap := MainDevice^^.gdPMap;
  907.         ScreenRowBytes := BitAnd(ScreenPixMap^^.rowBytes, $1fff);
  908.         ScreenBase := ScreenPixMap^^.baseAddr;
  909.     end;
  910.  
  911.  
  912.     procedure SetupMenus;
  913.         var
  914.             i: integer;
  915.     begin
  916.         AppleMenuH := GetMenu(AppleMenu);
  917.         InsertMenu(AppleMenuH, 0);
  918.         FileMenuH := GetMenu(FileMenu);
  919.         InsertMenu(FileMenuH, 0);
  920.         EditMenuH := GetMenu(EditMenu);
  921.         InsertMenu(EditMenuH, 0);
  922.         OptionsMenuH := GetMenu(OptionsMenu);
  923.         InsertMenu(OptionsMenuH, 0);
  924.         EnhanceMenuH := GetMenu(EnhanceMenu);
  925.         InsertMenu(EnhanceMenuH, 0);
  926.         AnalyzemenuH := GetMenu(AnalyzeMenu);
  927.         InsertMenu(AnalyzemenuH, 0);
  928.         SpecialMenuH := GetMenu(SpecialMenu);
  929.         InsertMenu(SpecialMenuH, 0);
  930.         StacksMenuH := GetMenu(StacksMenu);
  931.         InsertMenu(StacksMenuH, 0);
  932.         WindowsMenuH := GetMenu(WindowsMenu);
  933.         InsertMenu(WindowsMenuH, 0);
  934.  
  935.         FontMenuH := GetMenu(FontMenu);
  936.         InsertMenu(FontMenuH, -1);
  937.         SizeMenuH := GetMenu(SizeMenu);
  938.         InsertMenu(SizeMenuH, -1);
  939.         StyleMenuH := GetMenu(StyleMenu);
  940.         InsertMenu(StyleMenuH, -1);
  941.         BinaryMenuH := GetMenu(BinaryMenu);
  942.         InsertMenu(BinaryMenuH, -1);
  943.         ArithmeticMenuH := GetMenu(ArithmeticMenu);
  944.         InsertMenu(ArithmeticMenuH, -1);
  945.         BackgroundMenuH := GetMenu(BackgroundMenu);
  946.         InsertMenu(BackgroundMenuH, -1);
  947.         PropagateMenuH := GetMenu(PropagateMenu);
  948.         InsertMenu(PropagateMenuH, -1);
  949.         ColorTablesMenuH := GetMenu(ColorTablesMenu);
  950.         InsertMenu(ColorTablesMenuH, -1);
  951.         AcquireMenuH := GetMenu(AcquireMenu);
  952.         InsertMenu(AcquireMenuH, -1);
  953.         ExportMenuH := GetMenu(ExportMenu);
  954.         InsertMenu(ExportMenuH, -1);
  955.         FilterMenuH := GetMenu(FilterMenu);
  956.         InsertMenu(FilterMenuH, -1);
  957.  
  958.         TransferModeMenuH := GetMenu(TransferModeMenu);
  959.         InsertMenu(TransferModeMenuH, -1);
  960.  
  961.         LineToolMenuH := GetMenu(LineToolMenu);
  962.         InsertMenu(LineToolMenuH, -1);
  963.  
  964.         ImageMathOpsMenuH := GetMenu(ImageMathOpsMenu);
  965.         InsertMenu(ImageMathOpsMenuH, -1);
  966.  
  967.         ImageListMenuH := GetMenu(ImageListMenu);
  968.         InsertMenu(ImageListMenuH, -1);
  969.  
  970.         UnitsMenuH := GetMenu(UnitsMenu);
  971.         InsertMenu(UnitsMenuH, -1);
  972.  
  973.         DrawMenuBar;
  974.         AddResMenu(AppleMenuH, 'DRVR');
  975.         AddResMenu(FontMenuH, 'FONT');
  976.         NumFontItems := CountMItems(FontMenuH);
  977.     end;
  978.  
  979.  
  980.     procedure FindMonitors;
  981. {Generate a list of monitors so we can update the color tables of multiple monitors.}
  982. {This wouldn't be necessary if we were using the Palette Manager.}
  983.         var
  984.             nextDevice: GDHandle;
  985.     begin
  986.         nMonitors := 0;
  987.         nextDevice := GetDeviceList;
  988.         while nextDevice <> nil do begin
  989.                 if TestDeviceAttribute(nextDevice, screenDevice) and TestDeviceAttribute(nextDevice, screenActive) then
  990.                     if nextDevice^^.gdPmap^^.PixelSize = 8 then begin
  991.                             nMonitors := nMonitors + 1;
  992.                             Monitors[nMonitors] := nextDevice;
  993.                         end;
  994.                 nextDevice := GetNextDevice(nextDevice);
  995.             end; {while}
  996.     end;
  997.  
  998.  
  999.     procedure MakeGDevice;
  1000.   {Sets up an 8-bit  graphics environment for the off screen CGrafports used for image windows.}
  1001.         var
  1002.             DeviceRect: Rect;
  1003.             SaveDevice: GDHandle;
  1004.             DeviceClut: CTabHandle;
  1005.     begin
  1006.         SaveDevice := GetGDevice;
  1007.         SetRect(DeviceRect, 0, 0, 64, 64);
  1008.         DeviceClut := CTabHandle(GetResource('clut', 200));    { The grayscale LUT }
  1009.         DetachResource(Handle(DeviceClut));
  1010.         osGDevice := NewGDevice(0, -1);
  1011.         with osGDevice^^ do begin
  1012.                 gdId := 0;
  1013.                 gdType := clutType;
  1014.                 gdResPref := 3;
  1015.                 gdSearchProc := nil;
  1016.                 gdCompProc := nil;
  1017.                 gdFlags := $C401;                                            { 1100 0100 0000 0001 }
  1018.                 gdRect := DeviceRect;
  1019.                 with gdPMap^^ do begin
  1020.                         baseAddr := nil;
  1021.                         bounds := DeviceRect;
  1022.                         rowBytes := 64 + $8000;
  1023.                         pixelSize := 8;
  1024.                         cmpCount := 1;
  1025.                         cmpSize := 8;
  1026.                         DisposCTable(pmTable);        { dispose of old color table }
  1027.                     end;
  1028.             end;
  1029.         osGDevice^^.gdPMap^^.pmTable := DeviceClut;
  1030.         MakeITable(osGDevice^^.gdPMap^^.pmTable, osGDevice^^.gdITable, 3);
  1031.         SetGDevice(SaveDevice);
  1032.     end;
  1033.  
  1034.  
  1035.     function GetFolderDirID (parentFolderVRefNum: Integer; parentFolderDirID: LongInt; folderName: Str63; var folderDirID: LongInt): OSErr;
  1036.   {Given a folder's name, vRefNum, and parent dirID, find its dirID }
  1037.         var
  1038.             myCInfoPBRec: CInfoPBRec;
  1039.             retCode: OSErr;
  1040.     begin
  1041.         myCInfoPBRec.ioCompletion := nil;
  1042.         myCInfoPBRec.ioNamePtr := @folderName;
  1043.         myCinfoPBRec.ioVRefNum := parentFolderVRefNum;
  1044.         myCInfoPBRec.ioFDirIndex := 0; { use name, vRefNum, dirID }
  1045.         myCInfoPBRec.ioDrDirID := parentFolderDirID; { will be changed }
  1046.         retCode := PBGetCatInfoSync(@myCInfoPBRec); { IM IV-155 }
  1047.         if retCode = noErr then
  1048.             folderDirID := myCInfoPBRec.ioDrDirID;
  1049.         GetFolderDirID := retCode;
  1050.     end;
  1051.  
  1052.  
  1053.     procedure MyAppendMenu (menu: MenuHandle; item: integer; str: str255);
  1054.     begin
  1055.         AppendMenu(menu, ' ');
  1056.         SetItem(menu, item, str);
  1057.     end;
  1058.  
  1059.  
  1060.     procedure FindPlugIns;
  1061.         var
  1062.             err: OSErr;
  1063.             wdRefNum, index, SystemVRefNum: integer;
  1064.             name: Str255;
  1065.             ftype: OSType;
  1066.             PB: HParamBlockRec;
  1067.             ProcID, SystemDirID: LongInt;
  1068.             spec: FSSpec;
  1069.             pb2: WDPBRec;
  1070.             rCount, iFileRef: integer;
  1071.     begin
  1072.         if not System7 then
  1073.             exit(FindPlugIns);
  1074.         err := GetFolderDirID(LaunchVRefNum, LaunchDirID, 'Plug-Ins', PlugInsDirID);
  1075.         if err = NoErr then
  1076.             PlugInsVRefNum := LaunchVRefNum
  1077.         else if GetWDInfo(SystemRefNum, SystemVRefNum, SystemDirID, ProcID) = NoErr then
  1078.             if GetFolderDirID(SystemVRefNum, SystemDirID, 'Plug-Ins', PlugInsDirID) = NoErr then
  1079.                 PlugInsVRefNum := SystemVRefNum
  1080.             else
  1081.                 exit(FindPlugIns);
  1082.         err := OpenWD(PlugInsVRefNum, PlugInsDirID, 0, wdRefNum);
  1083.         if err <> NoErr then
  1084.             exit(FindPlugIns);
  1085.         index := 0;
  1086.         while true do begin
  1087.                 index := index + 1;
  1088.                 with PB do begin
  1089.                         ioCompletion := nil;
  1090.                         ioNamePtr := @name;
  1091.                         ioVRefNUm := wdRefNum;
  1092.                         ioVersNum := 0;
  1093.                         ioFDirIndex := index;
  1094.                         err := PBGetFInfo(@PB, false);
  1095.                         if err = fnfErr then
  1096.                             leave;
  1097.                     end;
  1098.                 spec.vrefnum := PluginsVRefNum;
  1099.                 spec.parID := PlugInsDirID;
  1100.                 spec.name := name;
  1101.                 iFileRef := FSpOpenResFile(spec, fsCurPerm);
  1102.                 if iFileRef <> -1 then begin
  1103.                         UseResFile(iFileRef);
  1104.                         rCount := Count1Resources('8BAM');
  1105.                         if rCount > 0 then begin
  1106.                                 nAcqPlugIns := nAcqPlugIns + 1;
  1107.                                 if nAcqPlugIns = 1 then
  1108.                                     SetItem(AcquireMenuH, 1, name)
  1109.                                 else
  1110.                                     MyAppendMenu(AcquireMenuH, nAcqPlugIns, name);
  1111.                             end;
  1112.                         rCount := Count1Resources('8BEM');
  1113.                         if rCount > 0 then begin
  1114.                                 nExportPlugIns := nExportPlugIns + 1;
  1115.                                 if nExportPlugIns = 1 then
  1116.                                     SetItem(ExportMenuH, 1, name)
  1117.                                 else
  1118.                                     MyAppendMenu(ExportMenuH, nExportPlugIns, name);
  1119.                             end;
  1120.                         rCount := Count1Resources('8BFM');
  1121.                         if rCount > 0 then begin
  1122.                                 nFilterPlugIns := nFilterPlugIns + 1;
  1123.                                 if nFilterPlugIns = 1 then
  1124.                                     SetItem(FilterMenuH, 1, name)
  1125.                                 else
  1126.                                     MyAppendMenu(FilterMenuH, nFilterPlugIns, name);
  1127.                             end;
  1128.                         CloseResFile(iFileRef);
  1129.                     end;
  1130.             end; {while}
  1131.         err := CloseWD(wdRefNum);
  1132.     end;
  1133.  
  1134.  
  1135.     procedure Init;
  1136.         var
  1137.             i: integer;
  1138.             p: SyspPtr;
  1139.             mbhp: ^integer;
  1140.             str: str255;
  1141.             err: OSErr;
  1142.     begin
  1143.         SetApplLimit(ptr(LongInt(GetApplLimit) - StackSize));
  1144.         MaxApplZone;
  1145.         InitGraf(@ThePort);
  1146.         InitFonts;
  1147.         InitWindows;
  1148.         InitCursor;
  1149.   {PLHeapInit(100000,5000,Nil,true,true)-Needed for MPW}
  1150.         TEInit;
  1151.         InitDialogs(@SysResume);
  1152.         CheckBits;
  1153.         FindMonitors;
  1154.         ScreenPort := GrafPtr(NewPtr(SizeOf(GrafPort)));
  1155.         OpenPort(ScreenPort);
  1156.         NoInfo := @NoInfoRec;
  1157.         Info := NoInfo;
  1158.         ValuesWindow := nil;
  1159.         with BlackRGB do begin
  1160.                 red := 0;
  1161.                 blue := 0;
  1162.                 green := 0;
  1163.             end;
  1164.         with WhiteRGB do begin
  1165.                 red := -1;
  1166.                 blue := -1;
  1167.                 green := -1;
  1168.             end;
  1169.         with NoInfo^ do begin
  1170.                 nlines := 0;
  1171.                 PixelsPerLine := 0;
  1172.                 ImageSize := 0;
  1173.                 PixMapSize := 0;
  1174.                 PicBaseAddr := nil;
  1175.                 PicBaseHandle := nil;
  1176.                 osPort := nil;
  1177.                 RoiShowing := false;
  1178.                 RoiType := NoRoi;
  1179.                 RoiRect := SrcRect;
  1180.                 roiRgn := NewRgn;
  1181.                 title := 'NoInfo';
  1182.                 Magnification := 1.0;
  1183.                 PictureType := NullPicture;
  1184.                 wptr := nil;
  1185.                 Changes := false;
  1186.                 BytesPerRow := 0;
  1187.                 SetRect(SrcRect, 0, 0, 0, 0);
  1188.                 PicRect := SrcRect;
  1189.                 wrect := SrcRect;
  1190.                 initwrect := wrect;
  1191.                 savewrect := wrect;
  1192.                 SaveSrcRect := SrcRect;
  1193.                 SaveMagnification := magnification;
  1194.                 savehloc := 0;
  1195.                 savevloc := 0;
  1196.                 ScaleToFitWindow := false;
  1197.                 nColors := 256;
  1198.                 ColorStart := 0;
  1199.                 ColorEnd := 255;
  1200.                 SaveColorStart := 0;
  1201.                 SaveColorEnd := 255;
  1202.                 FillColor1 := BlackRGB;
  1203.                 FillColor2 := BlackRGB;
  1204.                 SaveFill1 := BlackRGB;
  1205.                 SaveFill2 := BlackRGB;
  1206.                 LUTMode := GrayScale;
  1207.                 ColorTable := CustomTable;
  1208.                 InvertedColorTable := false;
  1209.                 xUnit := 'pixel';
  1210.                 xSpatialScale := 0.0;
  1211.                 ySpatialScale := 0.0;
  1212.                 PixelAspectRatio := 1.0;
  1213.                 SpatiallyCalibrated := false;
  1214.                 UnitOfMeasure := '';
  1215.                 PicNum := 1;
  1216.                 PidNum := 0;
  1217.                 HeaderOffset := -1;
  1218.                 ImageDataOffset := -1;
  1219.                 ColorMapOffset := -1;
  1220.                 for i := 0 to 255 do
  1221.                     ctable[i].value := 0;
  1222.                 Fit := Poly3;
  1223.                 DensityCalibrated := false;
  1224.                 ZeroClip := false;
  1225.                 nCoefficients := 0;
  1226.                 for i := 1 to 6 do
  1227.                     Coefficient[i] := 0.0;
  1228.                 BinaryPic := false;
  1229.                 WindowState := NormalWindow;
  1230.                 Revertable := false;
  1231.                 LX1 := -1.0;
  1232.                 LY1 := -1.0;
  1233.                 LX2 := -1.0;
  1234.                 LY2 := -1.0;
  1235.                 LAngle := 0.0;
  1236.                 IdentityFunction := false;
  1237.                 StackInfo := nil;
  1238.                 Thresholding := false;
  1239.                 iVersion := 0;
  1240.                 vref := 0;
  1241.                 DataType := EightBits;
  1242.                 AbsoluteMin := 0;
  1243.                 AbsoluteMax := 0;
  1244.                 CurrentMin := 0;
  1245.                 CurrentMax := 0;
  1246.                 LittleEndian := false;
  1247.                 DataH := nil;
  1248.             end;
  1249.         ExplicitPalette := NewPalette(256, nil, pmExplicit, 0);
  1250.         CScreenPort := CGrafPtr(NewPtr(SizeOf(CGrafPort)));
  1251.         OpenCPort(CScreenPort);
  1252.         SetPalette(WindowPtr(CScreenPort), ExplicitPalette, false);
  1253.         finished := false;
  1254.         FlushEvents(EveryEvent, 0);
  1255.         for i := 1 to 10 do
  1256.             MoreMasters;
  1257.         mbhp := pointer(MBarHeight);
  1258.         MenuBarHeight := mbhp^;
  1259.         SetRect(trect, tleft, ttop, tleft + twidth, ttop + theight);
  1260.         ToolWindow := NewCWindow(nil, trect, 'Tools', true, NoGrowDocProc, nil, false, 0);
  1261.         SetPalette(ToolWindow, ExplicitPalette, false);
  1262.         WindowPeek(ToolWindow)^.WindowKind := ToolKind;
  1263.         BringToFront(ToolWindow);
  1264.         ScreenWidth := ScreenBits.Bounds.right;
  1265.         ScreenHeight := ScreenBits.Bounds.bottom;
  1266.         SliceStart := 100;
  1267.         SliceEnd := 150;
  1268.         with SliceColor do begin
  1269.                 red := -1;
  1270.                 green := 0;
  1271.                 blue := 0;
  1272.             end;
  1273.         DensitySlicing := false;
  1274.         nExtraColors := 0;
  1275.         GrayMapReady := false;
  1276.         ResetGrayMap;   {LUT must be setup before InitMenus}
  1277.         InitMenus;
  1278.         SetRect(gmrect, gmleft, gmtop, gmleft + gmwidth, gmtop + gmheight);
  1279.         SetRect(gmSlide1, gmrectleft, gmrectbottom + gmSlide1Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide1Offset + gmSlideHeight);
  1280.         gmSlide1i := gmSlide1;
  1281.         InsetRect(gmSlide1i, 1, 1);
  1282.         SetRect(gmSlide2, gmrectleft, gmrectbottom + gmSlide2Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide2Offset + gmSlideHeight);
  1283.         gmSlide2i := gmSlide2;
  1284.         InsetRect(gmSlide2i, 1, 1);
  1285.         SetRect(gmIcon1, gmIcon1left, gmrectbottom + gmIconOffset, gmIcon1left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  1286.         SetRect(gmIcon2, gmIcon2left, gmrectbottom + gmIconOffset, gmIcon2left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  1287.         MapWindow := NewWindow(nil, gmrect, 'Map', true, NoGrowDocProc, nil, false, 0);
  1288.         WindowPeek(MapWindow)^.WindowKind := MapKind;
  1289.         SetRect(MapRect, gmRectLeft, gmRectTop, gmRectRight, gmRectBottom);
  1290.         MapRect2 := MapRect;
  1291.         InsetRect(MapRect2, -2, -2);
  1292.         cheight := 256 + (2 + nExtraColors) * ExtraColorsHeight;
  1293.         SetRect(crect, cleft, ctop, cleft + cwidth, ctop + cheight);
  1294.         LUTWindow := NewCWindow(nil, crect, 'LUT', true, NoGrowDocProc, nil, false, 0);
  1295.         SetPalette(LUTWindow, ExplicitPalette, false);
  1296.         WindowPeek(LUTWindow)^.WindowKind := LUTKind;
  1297.         rleft := 2;
  1298.         if ScreenHeight > 480 then
  1299.             rtop := ScreenHeight - rheight - 5
  1300.         else
  1301.             rtop := 358;
  1302.         SetRect(trect, rleft, rtop, rleft + rwidth, rtop + rheight);
  1303.         ValuesWindow := NewWindow(nil, trect, 'Values', true, NoGrowDocProc, nil, false, 0);
  1304.         BringToFront(ValuesWindow);
  1305.         WindowPeek(ValuesWindow)^.WindowKind := ValuesKind;
  1306.         BuggyWatch := GetCursor(WatchCursor);
  1307.         InitTools;
  1308.         MakeCursors;
  1309.         nPics := 0;
  1310.         nextPid := -1;
  1311.         HistoWindow := nil;
  1312.         PlotWindow := nil;
  1313.         IsInsertionPoint := false;
  1314.         MaskRgn := NewRgn;
  1315.         PlotPICT := nil;
  1316.         AutoscalePlots := true;
  1317.         InvertPlots := false;
  1318.         LinePlot := true;
  1319.         DrawPlotLabels := true;
  1320.         FixedSizePlot := false;
  1321.         ProfilePlotMin := 0;
  1322.         ProfilePlotMax := 255;
  1323.         ProfilePlotWidth := 300;
  1324.         ProfilePlotHeight := 150;
  1325.         SprayCanDiameter := 32;
  1326.         SprayCanRadius := 16;
  1327.         SprayCanRadius2 := 256;
  1328.         BrushWidth := 14;
  1329.         BrushHeight := 14;
  1330.         CurrentUndoSize := 0;
  1331.         p := GetSyspPtr;
  1332.         BlinkTime := BitAnd($000F, p^.volclik) * 4;
  1333.         MakePatterns;
  1334.         info^.LUTMode := GrayScale;
  1335.         PicLeftBase := twidth + cwidth + 10;
  1336.         PicTopBase := MenuBarHeight + 20;
  1337.         PicLeft := PicLeftBase;
  1338.         PicTop := PicTopBase;
  1339.         CurrentFontID := Helvetica;
  1340.         CurrentStyle := []; {plain}
  1341.         CurrentSize := 12;
  1342.         TextJust := teJustLeft;
  1343.         TextBack := NoBack;
  1344.         MouseState := NotInRoi;
  1345.         WhatsOnClip := NothingOnClip;
  1346.         InitExtraColors;
  1347.         OldScrapCount := GetScrapCount;
  1348.         ClipboardConverted := false;
  1349.         BufferSize := DefaultBufferSize;
  1350.         LookForFrameGrabbers;
  1351.         VideoChannel := 0;
  1352.         Digitizing := false;
  1353.         debugging := false;
  1354.         BlankFieldInfo := nil;
  1355.         InvertVideo := false;
  1356.         HighlightSaturatedPixels := false;
  1357.         PlotCount := 0;
  1358.         PlotAvg := 1;
  1359.         ActualPlotMin := 0.0;
  1360.         ActualPlotMax := 0.0;
  1361.         ClipTextInBuffer := false;
  1362.         TextBufP := TextBufPtr(NewPtr(SizeOf(TextBufType)));
  1363.         if TextBufP = nil then
  1364.             ExitToShell;
  1365.         MacrosP := MacrosPtr(NewPtr(SizeOf(MacrosRec)));
  1366.         if MacrosP = nil then
  1367.             ExitToShell;
  1368.         mCount := 0;
  1369.         mCount2 := 0;
  1370.         nPoints := 0;
  1371.         nLengths := 0;
  1372.         nAngles := 0;
  1373.         for i := 1 to MaxStandards do
  1374.             StandardValues[i] := BadReal;
  1375.         nStandards := 0;
  1376.         for i := 0 to 255 do
  1377.             cvalue[i] := i;
  1378.         WhatToUndo := NothingToUndo;
  1379.         WhatToCopy := NothingToCopy;
  1380.         PrintRecord := nil;
  1381.         printing := false;
  1382.         HalftoneFrequency := 53;
  1383.         HalftoneAngle := 45;
  1384.         HalftoneDotFunction := true;
  1385.         cr := chr(13);
  1386.         tab := chr(9);
  1387.         BackSpace := chr(8);
  1388.         eof := chr(4);
  1389.         measuring := false;
  1390.         measurements := [AreaM, MeanM];
  1391.         UpdateFitEllipse;
  1392.         nListColumns := 0;
  1393.         FramesToAverage := 16;
  1394.         NewPicWidth := 552;
  1395.         NewPicHeight := 436;
  1396.         RestoreUndoBuf := true;
  1397.         MaxScionWidth := 600;
  1398.         ThresholdToForeground := true;
  1399.         NonThresholdToBackground := true;
  1400.         SelectionMode := NewSelection;
  1401.         RoiMovementState := Unconstrained;
  1402.         PasteControl := nil;
  1403.         PasteTransferMode := SrcCopy;
  1404.         WhatToImport := ImportTIFF;
  1405.         ImportCustomWidth := 512;
  1406.         ImportCustomHeight := 512;
  1407.         ImportCustomSlices := 1;
  1408.         ImportCustomOffset := 0;
  1409.         ImportCustomDepth := EightBits;
  1410.         ImportSwapBytes := false;
  1411.         ImportCalibrate := true;
  1412.         ImportAll := false;
  1413.         ImportInvert := false;
  1414.         RoiNudged := false;
  1415.         ForegroundIndex := BlackIndex;
  1416.         BackgroundIndex := WhiteIndex;
  1417.         OpPending := false;
  1418.         RedoSelection := false;
  1419.         WandAutoMeasure := false;
  1420.         WandAdjustAreas := false;
  1421.         OptionKeyWasDown := false;
  1422.         BinaryIterations := 1;
  1423.         ScaleArithmetic := true;
  1424.         ValuesMessage := '';
  1425.         SaveAsWhat := asTIFF;
  1426.         ExportAsWhat := asRaw;
  1427.         AnalyzingParticles := false;
  1428.         RedirectSampling := false;
  1429.         MinParticleSize := 1;
  1430.         MaxParticleSize := 999999;
  1431.         LabelParticles := true;
  1432.         OutlineParticles := false;
  1433.         IgnoreParticlesTouchingEdge := false;
  1434.         IncludeHoles := false;
  1435.         SaveAllState := NoSaveAll;
  1436.         InvertYCoordinates := true;
  1437.         ContinuousHistogram := false;
  1438.         DrawLabels(' ', '', '');
  1439.         HistogramSliceStart := 0;
  1440.         HistogramSliceEnd := 255;
  1441.         RoiUpdateTime := 0;
  1442.         FieldWidth := 9;
  1443.         precision := 2;
  1444.         MeasurementToRedo := 0;
  1445.         nMacros := 0;
  1446.         macro := false;
  1447.         KernelsRefNum := 0;
  1448.         DefaultRefNum := 0;
  1449.         MacrosRefNum := 0;
  1450.         LaunchVRefNum := 0;
  1451.         LaunchDirID := 0;
  1452.         PlugInsVRefNum := 0;
  1453.         PlugInsDirID := 0;
  1454.         DefaultFileName := '';
  1455.         rsHScale := 1.0;
  1456.         rsVScale := 1.0;
  1457.         rsAngle := 0.0;
  1458.         rsMethod := NearestNeighbor;
  1459.         rsCreateNewWindow := true;
  1460.         rsInteractive := false;
  1461.         ImportAutoScale := true;
  1462.         ImportMin := 0.0;
  1463.         ImportMax := 255.0;
  1464.         InvertPixelValues := false;
  1465.         OscillatingMovies := false;
  1466.         DriverHalftoning := true;
  1467.         LivePasteMode := false;
  1468.         ShowCount := true;
  1469.         PasteControlLeft := ScreenWidth - pcwidth - 10;
  1470.         PasteControlTop := trunc(ScreenHeight * 0.2);
  1471.         MaxMeasurements := 256;
  1472.         ResultsLeft := PicLeftBase;
  1473.         ResultsTop := 56;
  1474.         UnsavedResults := false;
  1475.         MajorLabel := 'Major';
  1476.         MinorLabel := 'Minor';
  1477.         User1Label := 'User 1';
  1478.         User2Label := 'User 2';
  1479.         ShowHeadings := false;
  1480.         MakingLOI := false;
  1481.         LOIType := Straight;
  1482.         MakingStack := false;
  1483.         FramesWanted := 20;
  1484.         ScaleConvolutions := true;
  1485.         FasterBackgroundSubtraction := true;
  1486.         BallRadius := 50;
  1487.         DelayTicks := 0;
  1488.         CmdPeriodToStop := 'Type cmd-''.'' to stop.';
  1489.         CommandKey := chr(17);
  1490.         BinaryCount := 4;
  1491.         BinaryThreshold := BinaryCount * 255;
  1492.         ClipboardColor := BlackRGB;
  1493.         InitAngle := 0;                                             {default is one full revolution of volume}
  1494.         TotalAngle := 360;
  1495.         AngleInc := 10;                                           {in ten-degree increments}
  1496.         TransparencyUpper := 254;                      {default has only value 255 transparent}
  1497.         TransparencyLower := 0;
  1498.         DepthCueSurf := 0;                                     {default has full depth-cueing for surface}
  1499.         DepthCueInt := 50;                                     {components and 50% depth-cueing elsewhere}
  1500.         SaveProjections := FALSE;                         {by default, do not save and close projections}
  1501.         AxisOfRotation := xAxis;
  1502.         MinProjSize := TRUE;                                {by default, make all windows just big enough}
  1503.         ProjectionMethod := NearestPoint;
  1504.         MeterWindow := nil;
  1505.         nCoordinates := 0;
  1506.         CoordinatesWidth := 0;
  1507.         CoordinatesHeight := 0;
  1508.         CoordinatesRoiType := NoRoi;
  1509.         SwitchLUTOnSuspend := false;
  1510.         SumFrames := false;
  1511.         ShowIntegratedValues := false;
  1512.         FixIntegrationScale := false;
  1513.         IntegrationMin := 0;
  1514.         IntegrationMax := 4096;
  1515.         ExternalTrigger := false;
  1516.         BlindMovieCapture := false;
  1517.         LG3DacLow := DefaultLG3DacLow;
  1518.         LG3DacHigh := DefaultLG3DacHigh;
  1519.         VideoControl := nil;
  1520.         SyncMode := NormalSync;
  1521.         VideoRateAveraging := false;
  1522.         DitherColor := true;
  1523.         RGBLut := CustomLUT;
  1524.         with Highlight1 do begin
  1525.                 red := -1;
  1526.                 green := 0;
  1527.                 blue := 0;
  1528.             end;
  1529.         with Highlight254 do begin
  1530.                 red := -1;
  1531.                 green := -1;
  1532.                 blue := 0;
  1533.             end;
  1534.         HighlightMode := false;
  1535.         LegalWithoutImage := [UpdateLutC, StartC, ShowResultsC, GetPicSizeC, PutMsgC, ExitC, CaptureC, MoveToC, BeepC, MakeNewC, SetPaletteC, SetBackC, GetRoiC, OpenC, ImportC, SetImportC, SetMinMaxC, SetCustomC, nPicsC, WaitC, SetSizeC, TriggerC, AverageFramesC, SaveStateC, RestoreStateC, SetCounterC, MakeStackC, ShowMsgC, SetUser1C, SetUser2C, SetOptionsC, RequiresC];
  1536.         LegalWithoutImage := LegalWithoutImage + [DisposeAllC, GetTimeC, SetForeC, SetBackC, GetStringC, OpenSerialC, GetSerialC, PutSerialC, SetCursorC, TickCountC, ConcatC, SetVideoC, StringToNumC, ChannelC, AcquireC, UndoSizeC, FilterC, PhotoModeC, DrawTextC, WriteC, WritelnC, NewTextWindowC, UserCodeC, SelectWindowC, BitAndC, BitOrC, WindowTitleC, ScaleConvolutionsC];
  1537.         LegalWithoutImage := LegalWithoutImage + [SaveC, SaveAsC, CloseC, DisposeC, PosC];
  1538.         TopOfStack := 0;
  1539.         SerialBufferP := nil;
  1540.         MacroTicks := 0;
  1541.         OpeningPlugInWindow := false;
  1542.         LG3DacA := 0;
  1543.         LG3DacB := 0;
  1544.         LG3DataOut := 0;
  1545.         nAcqPlugIns := 0;
  1546.         nExportPlugIns := 0;
  1547.         nFilterPlugIns := 0;
  1548.         LastAcqPlugIn := '';
  1549.         LastFilterPlugIn := '';
  1550.         LastExportPlugIn := '';
  1551.         TextInfo := nil;
  1552.         nTextWindows := 0;
  1553.         NewTitle := 'Untitled';
  1554.         CurrentWPtr := nil;
  1555.         CurrentKind := 0;
  1556.         SearchString := '';
  1557.         TextCreator := 'Imag';
  1558.         CurrentMathOp := SubMath;
  1559.         MathSrc1 := 1;
  1560.         MathSrc2 := 1;
  1561.         MathGain := 0.5;
  1562.         MathOffset := 128;
  1563.         MathResult := 'Result';
  1564.         PrintOptionsSet := false;
  1565.         APReset := true;
  1566.         ShowPlot := true;
  1567.     end;
  1568.  
  1569.  
  1570. end.